<?php
include "../config/koneksi.php";
//include "../config/library.php";
//include "../config/fungsi_indotgl.php";
//include "../config/fungsi_combobox.php";
include "../config/class_paging.php";

$act=$_GET['act'];
if($act=='hapus'){
	//echo "woi : ";
	mysql_query("DELETE FROM guru WHERE nip='$_GET[nip]'");
	echo "<meta content='0;media.php?module=guru' http-equiv='refresh' /> ";
}
	
if(isset($_POST['submit']))
{
/*
    $nama_tamu = $_POST['nama_tamu'];
    $email_tamu = $_POST['email_tamu'];
    $judul = $_POST['judul'];
    $pesan_tamu = $_POST['pesan_tamu'];
    //echo "<b> $nama_tamu </b><br>";    
    //echo "<b> $email_tamu </b><br>";    
    //echo "<b> $judul </b><br>";    
    //echo "<b> $pesan_tamu </b><br>";    
	
	$query = mysql_query("insert into buku_tamu(nama_tamu, email_tamu, judul, pesan_tamu) values ('$nama_tamu', '$email_tamu','$judul','$pesan_tamu') ");
*/
	if($act=='input'){
		//echo "nip : " . $_POST[nip] . "<br>";
		
		$query = mysql_query("insert into guru (
		nip, nama, jenip_kelamin, agama, tempat_lahir, tanggal_lahir, berat_badan, tinggi_badan, ukuran_sepatu, ukuran_celana, ukuran_baju, alamat, rt, rw, desa, kecamatan, kota, kodepos, telp, provinsi, email, asal_sekolah, tahun_ajaran, no_skhun, nama_ayah, usia_ayah, pekerjaan_ayah, nama_ibu, usia_ibu, pekerjaan_ibu, jumlah_anak, anak_ke, penghasilan, ijazah, kelakuan_baik, skhun, keterangan_sehat, pasphoto, tidak_buta_warna) values 
		('$_POST[nip]', 
		'$_POST[nama]',
		'$_POST[jenip_kelamin]',
		'$_POST[agama]',
		'$_POST[tempat_lahir]',
		'$_POST[tanggal_lahir]',
		'$_POST[berat_badan]',
		'$_POST[tinggi_badan]',
		'$_POST[ukuran_sepatu]',
		'$_POST[ukuran_celana]',
		'$_POST[ukuran_baju]',
		'$_POST[alamat]',
		'$_POST[rt]',
		'$_POST[rw]',
		'$_POST[desa]',
		'$_POST[kecamatan]',
		'$_POST[kota]',
		'$_POST[kodepos]',
		'$_POST[telp]',
		'$_POST[provinsi]',
		'$_POST[email]',
		'$_POST[asal_sekolah]',
		'$_POST[tahun_ajaran]',
		'$_POST[no_skhun]',
		'$_POST[nama_ayah]',
		'$_POST[usia_ayah]',
		'$_POST[pekerjaan_ayah]',
		'$_POST[nama_ibu]',
		'$_POST[usia_ibu]',
		'$_POST[pekerjaan_ibu]',
		'$_POST[jumlah_anak]',
		'$_POST[anak_ke]',
		'$_POST[penghasilan]',
		'$_POST[ijazah]',
		'$_POST[kelakuan_baik]',
		'$_POST[skhun]',
		'$_POST[keterangan_sehat]',
		'$_POST[pasphoto]',
		'$_POST[tidak_buta_warna]' ) ");
		
		//echo "nip : " . $_POST[nama] . "<br>";
		echo "<meta content='0;media.php?module=guru' http-equiv='refresh' /> ";
	}
	
	if($act=='edit'){
		//echo "nip : " . $_POST[nip] . "<br>";
		
		mysql_query("UPDATE guru SET nama       = '$_POST[nama]',
                                   jenip_kelamin = '$_POST[jenip_kelamin]',
                                   agama = '$_POST[agama]',
                                   tempat_lahir = '$_POST[tempat_lahir]',
                                   tanggal_lahir = '$_POST[tanggal_lahir]',
                                   berat_badan = '$_POST[berat_badan]',
                                   tinggi_badan = '$_POST[tinggi_badan]',
                                   ukuran_sepatu = '$_POST[ukuran_sepatu]',
                                   ukuran_celana = '$_POST[ukuran_celana]',
                                   ukuran_baju = '$_POST[ukuran_baju]',
                                   alamat = '$_POST[alamat]',
                                   rt = '$_POST[rt]',
                                   rw = '$_POST[rw]',
                                   desa = '$_POST[desa]',
                                   kecamatan = '$_POST[kecamatan]',
                                   kota = '$_POST[kota]',
                                   kodepos = '$_POST[kodepos]',
                                   telp = '$_POST[telp]',
                                   provinsi = '$_POST[provinsi]',
                                   email = '$_POST[email]',
                                   asal_sekolah = '$_POST[asal_sekolah]',
                                   tahun_ajaran = '$_POST[tahun_ajaran]',
                                   no_skhun = '$_POST[no_skhun]',
                                   nama_ayah = '$_POST[nama_ayah]',
                                   usia_ayah = '$_POST[usia_ayah]',
                                   pekerjaan_ayah = '$_POST[pekerjaan_ayah]',
                                   nama_ibu = '$_POST[nama_ibu]',
                                   usia_ibu = '$_POST[usia_ibu]',
                                   pekerjaan_ibu = '$_POST[pekerjaan_ibu]',
                                   jumlah_anak = '$_POST[jumlah_anak]',
                                   anak_ke = '$_POST[anak_ke]',
                                   penghasilan = '$_POST[penghasilan]',
                                   ijazah = '$_POST[ijazah]',
                                   kelakuan_baik = '$_POST[kelakuan_baik]',
                                   skhun = '$_POST[skhun]',
                                   keterangan_sehat = '$_POST[keterangan_sehat]',
                                   pasphoto = '$_POST[pasphoto]',
                                   tidak_buta_warna = '$_POST[tidak_buta_warna]'
                             WHERE nip   = '$_POST[nip]'");
		
		//echo "nip : " . $_POST[nama] . "<br>";
		echo "<meta content='0;media.php?module=guru' http-equiv='refresh' /> ";
	}
	
	
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SMK Pasundan Rancaekek</title>

<link href="../css/templatemo_style.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" type="text/css" href="../css/ddsmoothmenu.css" />
<script type="text/javascript" src="../scripts/jquery.min.js"></script>
<script type="text/javascript" src="../scripts/ddsmoothmenu.js">

</script>

<script type="text/javascript">

ddsmoothmenu.init({
	mainmenuid: "templatemo_menu", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	//customtheme: ["#1c5a80", "#18374a"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

</script>
</head>

<body id="subpage">

<div id="templatemo_outer_sub_wrapper">
	<div id="templatemo_sub_wrapper">
    
    	<div id="templatemo_header_admin">		
            <?php
			include "menu_admin.php";
			?>
            <div class="cleaner"></div>

        </div> <!-- end of templatemo header -->
        
        <div id="templatemo_main">
        
          	<div class="col_w960 col_w960_last">
				<div class="col_w300 float_r">
                
                    <h3>Tentang Sekolah</h3>
                    <?php 
					include "menu_kiri.php";
					?>
                
                </div>  
                <div class="col_w600 float_l">
                    
                    <h2>Data Guru</h2>
        		<input type=button value='Data Guru' onclick="window.location.href='?module=guru'">
        		<input type=button value='Tambah Guru' onclick="window.location.href='?module=guru&act=tambahguru'">
				
        		<div id="contact_form">
				<?php
				switch($_GET[act]){
				default:
					echo "
          <form method=get action='$_SERVER[PHP_SELF]'>
          <input type=hidden name=module value=guru>
          <div id=paging>Masukkan Nama Guru : <input type=text name='nama'> <input type=submit value=Cari></div>
          </form>";

    if (empty($_GET['nama'])){
    echo "<table class='ijo'>  
          <tr id='ijo'><th>No</th><th>Nip</th><th>Nama</th> <th></th></tr>";

    $p      = new Paging;
    $batas  = 15;
    $posisi = $p->cariPosisi($batas);

    //$tampil = mysql_query("SELECT s.*, k.kelas, k.sub_kelas FROM guru s, guru_kelas sk, kelas k WHERE s.nip = sk.nip AND sk.kd_kelas = k.kd_kelas ORDER BY nip ASC LIMIT $posisi,$batas");
    $tampil = mysql_query("SELECT * from guru ORDER BY nip ASC LIMIT $posisi,$batas");
    
  
    $no = $posisi+1;
    while($r=mysql_fetch_array($tampil)){      
      echo "<tr><td>$no</td>
                <td>$r[nip]</td>
                <td>$r[nama]</td>                
		            <td><a href=?module=guru&act=editguru&nip=$r[nip]>Edit</a> | 
		                <a href='$aksi?module=guru&act=hapus&nip=$r[nip]' onClick=\"return confirm('Anda yakin akan menghapus $r[nama]?')\">Hapus</a></td>
		        </tr>";
      $no++;
    }
    echo "</table>";

    $jmldata = mysql_num_rows(mysql_query("SELECT * FROM guru"));
      
    $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
    $linkHalaman = $p->navHalaman($_GET[halaman], $jmlhalaman);

    echo "<div id=paging>$linkHalaman</div><br>";
 
    break;    
    }
    else{
    echo "<table>  
          <tr><th>No</th><th>N ip</th><th>Nama</th><th>aksi</th></tr>";

    $p      = new Paging9;
    $batas  = 15;
    $posisi = $p->cariPosisi($batas);

    $tampil = mysql_query("SELECT * FROM guru WHERE nama LIKE '%$_GET[nama]%' ORDER BY nip ASC LIMIT $posisi,$batas");
      
    $no = $posisi+1;
    while($r=mysql_fetch_array($tampil)){
      echo "<tr><td>$no</td>
                <td>$r[nip]</td>
                <td>$r[nama]</td>                
		            <td><a href=?module=guru&act=editguru&nip=$r[nip]>Edit</a> | 
		                <a href='$aksi?module=guru&act=hapus&nip=$r[nip]'>Hapus</a></td>
		        </tr>";
      $no++;
    }
    echo "</table>";

    $jmldata = mysql_num_rows(mysql_query("SELECT * FROM guru WHERE nama LIKE '%$_GET[nama]%'"));
    
    $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
    $linkHalaman = $p->navHalaman($_GET[halaman], $jmlhalaman);

    echo "<div id=paging>$linkHalaman</div><br>";
 
    break;    
    }
					break;
				case "tambahguru":
					?>
					<form method="post" name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>?module=guru&act=input">
                        
						<table class='putih' border="0" width="650">
						<tr>
						<td colspan="4">
						<ul class="templatemo_list">
						<li><strong>DATA DIRI</strong></li>
						</ul>
						</td>
						</tr>
						<tr>
						<td>NIP</td> <td colspan="3"> <input type="text" name="nip" size="10" /> </td>                        
						</tr>
						<tr>
						<td>Nama Guru </td> <td colspan="3"> <input type="text" name="nama" size="30" /> </td>                        
						</tr>
						
						<tr>
						<td>Jenip Kelamin </td> <td colspan="3">
						<?php
						echo "<input type=radio name='jenip_kelamin' value='L' checked>Laki-Laki ";
						echo "<input type=radio name='jenip_kelamin' value='P'> Perempuan ";
						?>
						</td>                        
						</tr>
						
						<tr>
						<td>Agama </td> <td colspan="3">
						<?php
						echo "
						<select name='agama'>"; 
							  $tampil=mysql_query("SELECT * FROM agama");
							  while($w=mysql_fetch_array($tampil)){
								echo "<option value=$w[id_agama]>$w[nama_agama]</option>";								
							  }

						echo "</select>";
						?>
						</td>                        
						</tr>
						
						<tr>
						<td>Tempat Lahir </td> <td colspan="3"> <input type="text" name="tempat_lahir" size="20" /> </td>                        
						</tr>
						
						<tr>
						<td>Tgl Lahir </td> <td colspan="3"> <input type="text" name="tanggal_lahir" size="20" /> </td>                        
						</tr>
                        
                        
						<tr>
						<td>Alamat </td> <td colspan="3"><input type="text" name="alamat" size="60" /> </td>                        
						</tr>
						
						<tr>
						<td colspan="4">
						<ul class="templatemo_list">
						<li><strong>PENDIDIKAN</strong></li>
						</ul>
						</td>
						</tr>
						<tr> <td>Pendidikan Terakhir </td> <td colspan="3"><input type="text" name="pendidikan_terakhir" size="50" /> </td> </tr>
						<tr> <td>Jurusan</td> <td colspan="3"><input type="text" name="jurusan" size="50" value="<?php echo $r[jurusan]; ?>"/> </td> </tr>
												
						
						<tr>
						<td>Telp </td> <td colspan="3"> <input type="text" name="telp" size="20" value="<?php echo $r[telp]; ?>"/> </td>                        
						</tr>
						
						<tr>
						<td>						
						</td>
						<td colspan="3">				
                        <input type="submit" value="Simpan" id="submit" name="submit" class="submit_btn float_l" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_l" />
						</td>						
						</tr>
						</table>					
                    </form>
					<?php
					break;
					
				case "editguru":
				$edit = mysql_query("SELECT * FROM guru WHERE nip='$_GET[nip]' ");
				$r    = mysql_fetch_array($edit);
					?>
					<form method="post" name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>?module=guru&act=edit">
                        
						<table class='putih' border="0" width="650">
						<tr>
						<td colspan="4">
						<ul class="templatemo_list">
						<li><strong>DATA DIRI</strong></li>
						</ul>
						</td>
						</tr>
						<tr>
						<td>NIP</td> <td colspan="3"> <input type="text" readonly name="nip" size="10" value="<?php echo $r[nip]; ?>" /> </td>                        
						</tr>
						<tr>
						<td>Nama Guru </td> <td colspan="3"> <input type="text" name="nama" size="30" value="<?php echo $r[nama]; ?>"/> </td>                        
						</tr>
						
						<tr>
						<td>Jenip Kelamin </td> <td colspan="3">
						<?php
						if ($r[jenip_kelamin]=='L'){
							echo "<input type=radio name='jenip_kelamin' value='L' checked>Laki-Laki ";
							echo "<input type=radio name='jenip_kelamin' value='P'> Perempuan ";
						}else{
							echo "<input type=radio name='jenip_kelamin' value='L'>Laki-Laki ";
							echo "<input type=radio name='jenip_kelamin' value='P' checked>Perempuan ";
						}
						?>
						</td>                        
						</tr>
						
						<tr>
						<td>Agama </td> <td colspan="3">
						<?php
						echo "
						<select name='agama'>"; 
							  $tampil=mysql_query("SELECT * FROM agama");
							  while($w=mysql_fetch_array($tampil)){
								if ($r[agama]==$w[id_agama]){
								  echo "<option value=$w[id_agama] selected>$w[nama_agama]</option>";
								}
								else{
								  echo "<option value=$w[id_agama]>$w[nama_agama]</option>";
								}
							  }

						echo "</select>";
						?>
						</td>                        
						</tr>
						
						<tr>
						<td>Tempat Lahir </td> <td colspan="3"> <input type="text" name="tempat_lahir" size="20" value="<?php echo $r[tempat_lahir]; ?>"/> </td>                        
						</tr>
						
						<tr>
						<td>Tgl Lahir </td> <td colspan="3"> <input type="text" name="tanggal_lahir" size="20" value="<?php echo $r[tanggal_lahir]; ?>" /> </td>                        
						</tr>
                        
                        
						<tr>
						<td>Alamat </td> <td colspan="3"><input type="text" name="alamat" size="60" value="<?php echo $r[alamat]; ?>"/> </td>                        
						</tr>
						
						<tr>
						<td colspan="4">
						<ul class="templatemo_list">
						<li><strong>PENDIDIKAN</strong></li>
						</ul>
						</td>
						</tr>
						<tr> <td>Pendidikan Terakhir </td> <td colspan="3"><input type="text" name="pendidikan_terakhir" size="50" value="<?php echo $r[pendidikan_terakhir]; ?>"/> </td> </tr>
						<tr> <td>Jurusan</td> <td colspan="3"><input type="text" name="jurusan" size="50" value="<?php echo $r[jurusan]; ?>"/> </td> </tr>
												
						
						<tr>
						<td>Telp </td> <td colspan="3"> <input type="text" name="telp" size="20" value="<?php echo $r[telp]; ?>"/> </td>                        
						</tr>
						
						<tr>
						<td>						
						</td>
						<td colspan="3">				
                        <input type="submit" value="Simpan" id="submit" name="submit" class="submit_btn float_l" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_l" />
						</td>						
						</tr>
						</table>
                    </form>
					<?php
					break;
					
				
				}
				?>				
        		</div>
                </div>
                
            	<div class="cleaner"></div>   
            </div>        
        </div>
    
    </div> <!-- end of templatemo_wrapper -->
</div> <!-- end of templatemo_outer_wrapper -->

<?php
	include "../footer.php";
?>

</body>
</html>
